package com.human.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.human.entity.Emptrain;
import com.human.dao.EmptrainMapper;
import com.human.entity.ResultVo;
import com.human.service.IEmptrainService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 员工培训 服务实现类
 * </p>
 *
 * @author jzq
 * @since 2023-03-09
 */
@Service
public class EmptrainServiceImpl extends ServiceImpl<EmptrainMapper, Emptrain> implements IEmptrainService {

    @Resource
    EmptrainMapper emptrainMapper;

    @Override
    public ResultVo<Page> page(int current, int pageSize, String name) {
        //分页构造器
        Page pageInfo = new Page(current, pageSize);

        //执行查询
        IPage emptrainAndEmp = emptrainMapper.getEmptrainAndEmp(pageInfo, name);
        return new ResultVo<Page>(true, "查询成功", emptrainAndEmp);
    }

    @Override
    public ResultVo getEmptrainById(Integer id) {
        Emptrain emptrain = emptrainMapper.selectById(id);
        return new ResultVo(true, "查询成功", emptrain);
    }

    @Override
    public ResultVo getAllEmptrains() {
        List<Emptrain> emptrainList = emptrainMapper.selectList(null);
        return new ResultVo(true, "查询成功", emptrainList);
    }

    @Override
    public ResultVo addEmptrain(Emptrain emptrain) {
        int i = emptrainMapper.insert(emptrain);
        if (i > 0) {
            return new ResultVo(true, "添加成功");
        }
        return new ResultVo(false, "添加失败");
    }

    @Override
    public ResultVo updateEmptrain(Emptrain emptrain) {
        int i = emptrainMapper.updateById(emptrain);
        if (i > 0) {
            return new ResultVo(true, "修改成功");
        }
        return new ResultVo(false, "修改失败");
    }

    @Override
    public ResultVo deleteEmptrainById(Integer id) {
        int i = emptrainMapper.deleteById(id);
        if (i > 0) {
            return new ResultVo(true, "删除成功");
        }
        return new ResultVo(false, "删除失败");
    }

}
